//
//  peopleDetails.m
//  YaoHeAPP
//
//  Created by xyh on 16/3/9.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "peopleDetails.h"
#import "Controller.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface peopleDetails ()
{

    UIButton*phoneBtnz;
    UIButton* again_Btn;
    
    UIView *fristView;
    UIImageView *userimage;
    UILabel *name;
    UILabel *iphoneNUM;
    UIImageView *smailImage;

    UIView *towView;
    UILabel *zhiwei;
    UILabel *zhiweitext;
    UILabel *yeji;
    UILabel *yejitext;
    
    NSInteger stay;
    
}
@end

@implementation peopleDetails

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"peopleDetails"];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"peopleDetails"];
    
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    UIView*navcBar=[[UIView alloc]init];
    navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:navcBar];
    [self.view bringSubviewToFront:navcBar];
    [navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(60);  make.right.offset(0);
    }];
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=@"个人资料";
    titleLabel.font=Font(17);
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(self.view.frame.size.width/2-50);
        make.width.offset(100);
        make.height.offset(30);
    }];
    
    //返回按钮
    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backUp) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(6);
        make.width.offset(24);
        make.height.offset(22);
        make.bottom.offset(-12);
    }];
    
    
    
    //电话找货按钮
    phoneBtnz=[UIButton buttonWithType:UIButtonTypeCustom];
    phoneBtnz.layer.masksToBounds=YES;
    phoneBtnz.layer.cornerRadius=18;
    [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"Phone_call_for_goods"] forState:UIControlStateNormal];
    [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"phoneFindHF"] forState:UIControlStateHighlighted];
    [phoneBtnz addTarget:self action:@selector(callPhone) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:phoneBtnz];
    [phoneBtnz mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.height.offset(36);
        make.width.offset(36);
        make.bottom.offset(-12);
    }];
    
    //移除
    again_Btn=[UIButton buttonWithType:UIButtonTypeCustom];
    again_Btn.layer.masksToBounds=YES;
    again_Btn.layer.cornerRadius=20;
    again_Btn.backgroundColor=[UIColor colorWithRed:244.f/255.f green:244.f/255.f blue:244.f/255.f alpha:1];
    [again_Btn addTarget:self action:@selector(removeBtn) forControlEvents:UIControlEventTouchUpInside];
    [again_Btn setTitle:@"移除" forState:UIControlStateNormal];
    [again_Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:again_Btn];
    [again_Btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phoneBtnz.mas_right).offset(10);
        make.right.offset(-20);
        make.height.offset(36);
        make.bottom.offset(-12);
    }];

    
    //绘制界面
    fristView=[[UIView alloc]init];
    fristView.frame=CGRectMake(0, 60, self.view.frame.size.width, 120);
    fristView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:fristView];
    
    userimage=[[UIImageView alloc]init];
    userimage.frame=CGRectMake(15, 20, 80, 80);
    userimage.layer.masksToBounds=YES;
    userimage.layer.cornerRadius=40;
    [fristView addSubview:userimage];
    
    name=[[UILabel alloc]init];
    name.frame=CGRectMake(100, 30, self.view.frame.size.width-130, 30);
    name.font=[UIFont systemFontOfSize:16];
    name.textAlignment=NSTextAlignmentLeft;
    name.textColor=[UIColor colorWithRed:102.f/255.f green:102.f/255.f blue:102.f/255.f alpha:1];
    [fristView addSubview:name];
    
    //手机图片
    UIImageView *iponv=[[UIImageView alloc]init];
    iponv.image=[UIImage imageNamed:@"iphone"];
    //        iponv.backgroundColor=[UIColor grayColor];
    iponv.frame=CGRectMake(100, 60, 21, 30);
    [fristView addSubview:iponv];
    
    iphoneNUM=[[UILabel alloc]init];
    iphoneNUM.frame=CGRectMake(135, 60, self.view.frame.size.width-150, 30);
    iphoneNUM.font=[UIFont systemFontOfSize:16];
    iphoneNUM.textAlignment=NSTextAlignmentLeft;
    iphoneNUM.textColor=[UIColor colorWithRed:153.f/255.f green:153.f/255.f blue:153.f/255.f alpha:1];
    [fristView addSubview:iphoneNUM];
    
    smailImage=[[UIImageView alloc]init];
    smailImage.frame=CGRectMake(self.view.frame.size.width-15-52, 10, 52, 17);
//    smailImage.image=
    [fristView addSubview:smailImage];
    
    
    
    
    towView=[[UIView alloc]init];
    towView.frame=CGRectMake(0, 190, self.view.frame.size.width, 100);
    towView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:towView];
    
    zhiwei=[[UILabel alloc]init];
    zhiwei.frame=CGRectMake(10, 5, self.view.frame.size.width-20, 40);
    zhiwei.font=[UIFont systemFontOfSize:14];
    zhiwei.textAlignment=NSTextAlignmentLeft;
    zhiwei.textColor=[UIColor blackColor];
    [towView addSubview:zhiwei];
    
    //分割线
    UIView *imfen=[[UIView alloc]init];
    imfen.frame=CGRectMake(10, 50, self.view.frame.size.width-10, 0.5);
    imfen.backgroundColor=[UIColor grayColor];
    [towView addSubview:imfen];
    
    yeji=[[UILabel alloc]init];
    yeji.frame=CGRectMake(10, 55, self.view.frame.size.width-20, 40);
    yeji.font=[UIFont systemFontOfSize:14];
    yeji.textAlignment=NSTextAlignmentLeft;
    yeji.textColor=[UIColor blackColor];
    [towView addSubview:yeji];

    
    
    
    [self updata];

    
    
    

}
-(void)updata
{

    NSMutableDictionary *stringDic=[[NSMutableDictionary alloc]init];
    
    [stringDic setValue:self.userID forKey:@"USER_ID"];
    [stringDic setValue:self.CompayID forKey:@"COMPANY_ID"];

    
    [Controller requestWithURL:PEOPLEINF jsondic:stringDic finishBlock:^(ClassData* data) {
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]])
        {
            //赋值
            [userimage sd_setImageWithURL:[NSURL URLWithString:data.data[@"LOGO_PATH"]] placeholderImage:[UIImage imageNamed:@"default_head"]];
            name.text=data.data[@"REG_NAME"];
            iphoneNUM.text=data.data[@"REG_MOBILE"];
            
            stay=[data.data[@"REG_TYPE"] integerValue];
            
            if (stay==10) {
                //主账号
                smailImage.image=[UIImage imageNamed:@"putongzhanghao"];
            }else{
               //普通账号
                smailImage.image=[UIImage imageNamed:@"zhuzhanghao"];
            }
            
            zhiwei.text=[NSString stringWithFormat:@"职位：    %@",data.data[@"REG_TITLE"]];
            yeji.text=[NSString stringWithFormat:@"业绩：    共发布%@单，成功%@单",data.data[@"PURCHASE_NUM"],data.data[@"SUCCESS_NUM"]];
            
        }
        else
        {
            
        }
    }];




}

//点击按钮，拨打电话
-(void)callPhone
{
    //进入打电话页面
    UIWebView *webview = [[UIWebView alloc] init];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:4008850051"]]];
    [self.view addSubview:webview];
    //[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://4008850051"]];
}

//点击移除按钮
-(void)removeBtn
{
    
    
    //先判断是不是自己；（自己不可移除自己）
    
    if (stay==10) {
        
        ALERTSHOW(@"不可移除自己");
    }else{
    

    NSMutableDictionary *stringDic1=[[NSMutableDictionary alloc]init];
    
    [stringDic1 setValue:self.userID forKey:@"USER_ID"];

    [Controller requestWithURL:DELETEPEOPLE jsondic:stringDic1 finishBlock:^(ClassData* data) {
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]])
        {
            ALERTSHOW(@"移除成功");
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"PeopleDetails_view_deletail" object:nil];
            
            [self.navigationController popViewControllerAnimated:YES];
  
        }
        else
        {
            
        }
    }];
    }

}

//返回上个界面
-(void)backUp
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
